package com.chiangleoi.appointment.utils;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.chiangleoi.appointment.model.SiteInfo;
import com.chiangleoi.appointment.model.Venue;

import java.util.ArrayList;
import java.util.List;

public class SubscribeUtils {

    public List<SiteInfo> getSubscribeList() {
        String url = "https://jntyzx.cn:8443/GYM-JN/multi/Subscribe/getSubscribeByTomorrow?isWeekend=1&gid=03";
//        String url = "https://jntyzx.cn:8443/GYM-JN/multi/Subscribe/getSubscribeByToday?isWeekend=1&gid=03";
        String json = HttpUtil.createGet(url).execute().body();
        //  log.info("时间:{},json:{}", bookTime, json);
        JSONObject jsonObject = JSONObject.parseObject(json);
        Integer code = jsonObject.getInteger("code");
        List<SiteInfo> siteInfos = new ArrayList<>();
        if (code != null && code.equals(200)) {
            JSONObject result = jsonObject.getJSONObject("result");
            String venue1 = result.getString("venue");
            List<Venue> venues = JSONArray.parseArray(venue1, Venue.class);
            for (Venue venue : venues) {
                List<SiteInfo> sitePosition = venue.getSitePosition();
                for (SiteInfo siteInfo : sitePosition) {
                    siteInfo.setId(null);
                    siteInfos.add(siteInfo);
                }
            }
        }
        return siteInfos;
    }

}
